using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Train : MonoBehaviour
{
    // Rigidbody rigidbody;
    public float defaultAcc;
    public float defaultSpeed;
    public float currSpeed;
    public float maxSpeed;
    float acc;

    void Start()
    {
        currSpeed = defaultSpeed;
        //defaultSpeed = 1f;
        // rigidbody = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        Move();
    }

    void Move()
    {
        if (acc == 0 && currSpeed > defaultSpeed)
        {
            currSpeed -= defaultAcc;

            if (currSpeed < defaultSpeed)
                currSpeed = defaultSpeed;
        }
        else
        {
            currSpeed += acc;
            if (currSpeed > maxSpeed)
            {
                currSpeed = maxSpeed;
            }
        }


        // rigidbody.MovePosition(transform.position + new Vector3 (0,0,currSpeed) * Time.fixedDeltaTime);
    }

    public void SetAcc(float acc)
    {
        this.acc = acc;
        GameManger.instance.SetRealAcc(acc);
    }
}
